
#version 430

#ifdef GL_ES
precision mediump float;
#endif



uniform sampler2D U_Texture;//纹理采样器，读取纹理像素
//uniform vec4 U_Ambientcolor;
//uniform vec4 U_AmbientMaterial; 

varying vec4 V_Color;
varying vec2 V_Texcoord;
varying vec3 V_Normal;
varying vec4 V_WorldPos;
uniform vec4 U_CameraPos;
void main()
{
  //ambient
  vec4 AmbientLightcolor=vec4(0.8,0.8,0.8,1.0);
  vec4  AmbientMaterial=vec4(0.3,0.3,0.3,1.0);
  vec4  Ambientcolor =AmbientLightcolor*AmbientMaterial;
  //duffus 
  vec3 lightPos =vec3(10.0,10.0,50.0);
  vec3 L =lightPos;
  L=normalize(lightPos);
  vec3 N=normalize(V_Normal);
  
  vec4 DiffuedLightColor=vec4(1.0,1.0,1.0,1.0);
  vec4  DiffuseMaterial=vec4(0.8,0.8,0.8,1.0);

  vec4 Diffusecolor =DiffuedLightColor*DiffuseMaterial*max(0.0,dot(L,N));
  
  //specular
	vec4 SpecularLightColor=vec4(1.0,1.0,1.0,1.0);
	vec4 SpecularMaterial=vec4(0.5,0.5,0.5,1.0);
	vec3 reflectDir=normalize(reflect(-L,N));
	//inverse view direction
	vec3 viewDir=normalize(U_CameraPos.xyz-V_WorldPos.xyz);
   vec4 specularColor=SpecularLightColor*SpecularMaterial*pow(max(0.0,dot(viewDir,reflectDir)),32.0);
  
  
  
  //gl_FragColor=texture2D(U_Texture,V_Texcoord)*(Diffusecolor);
  gl_FragColor=texture2D(U_Texture,V_Texcoord)*(Diffusecolor+specularColor+Diffusecolor);
   //gl_FragColor=vec4(1.0f,1.0f,1.0f,1.0f);
}